<template>
	<section>
		<el-form :model="detail" label-width="120px" ref="detail" style="margin-top:20px;">
			<el-form-item label="任务状态：" style="color: #20a0ff;">
				{{detali_status(obtainStatus)}}
			</el-form-item>
			<!-- <el-form-item label="委托方昵称：">
				{{detail.taskNick}}
			</el-form-item>
			<el-form-item label="委托方手机号：">
				{{detail.taskAccount}}
			</el-form-item>
			<el-form-item label="委托方邮箱：">
				{{detail.taskEmail}}
			</el-form-item> -->
			<el-form-item label="执行方昵称：">
				{{detail.obtainNick}}
			</el-form-item>
			<el-form-item label="执行方手机号：">
				{{detail.obtainAccount}}
			</el-form-item>
			<el-form-item label="执行方邮箱：">
				{{detail.obtainEmail}}
			</el-form-item>

			<el-form-item label="任务名称：">
				{{detail.name}}
			</el-form-item>
			<el-form-item label="任务类型：">
				{{detail.type}}
			</el-form-item>
			<el-form-item label="截止日期：">
				{{detail.closeDate}} {{detail.closeTime}}
			</el-form-item>
			<el-form-item label="任务定价：">
				{{detail.reward}}
			</el-form-item>
			<el-form-item label="任务需求：">
				{{detail.instruction}}
			</el-form-item>
			<el-form-item label="任务配图：">
				<img :src="detail.cover" height="100" width="100" style="vertical-align: middle;margin: 5px 0;" />
			</el-form-item>
			<el-form-item label="字数要求：">
				{{detail.numberRequirement}}
			</el-form-item>
			<el-form-item label="提交须知：">
				{{detail.notes}}
			</el-form-item>
		</el-form>
		<el-form :model="applyDetail" label-width="120px" v-if="obtainStatus == 6">
			<el-form-item label="取消事由：">
				{{applyDetail.applyInstruct}}
			</el-form-item>
			<el-form-item label="任务状态：">
				{{task_status(applyDetail.taskStatus)}}
			</el-form-item>
		</el-form>
		<el-form :model="applyDetail" label-width="120px" v-if="obtainStatus == 2">
			<el-form-item label="修改建议：">
				<el-input type="textarea" v-model="instruction1" placeholder="修改建议"></el-input>
			</el-form-item>
		</el-form>
		<el-form :model="applyDetail" label-width="120px" v-if="obtainStatus == 3">
			<el-form-item label="延期事由：">
				{{applyDetail.applyInstruct}}
			</el-form-item>
			<el-form-item label="新时限：">
				{{applyDetail.applyCloseDate}} {{applyDetail.applyCloseTime}}
			</el-form-item>
			<el-form-item label="任务状态：">
				{{task_status(applyDetail.taskStatus)}}
			</el-form-item>
			<el-form-item label="反馈意见：">
				<el-input type="textarea" v-model="instruction" placeholder="反馈意见"></el-input>
			</el-form-item>
		</el-form>

		<div slot="footer" class="dialog-footer" v-if="obtainStatus == 0">

		</div>
		<div slot="footer" style="padding-left: 50px;" class="dialog-footer" v-else-if="obtainStatus == 1">
			<el-button type="primary" @click="goconfirmTask" >已经确认成品</el-button>
		</div>
		<div slot="footer" style="padding-left: 50px;" class="dialog-footer" v-else-if="obtainStatus == 2">
			<el-button type="primary" @click="goupdateTask('0')" >成品不合格</el-button>
			<el-button type="primary" @click="goupdateTask('1')" >成品合格</el-button>
		</div>
		<div slot="footer" style="padding-left: 50px;" class="dialog-footer" v-else-if="obtainStatus == 3">
			<el-button type="primary" @click="godelayTask('1')" >不同意申请</el-button>
			<el-button type="primary" @click="godelayTask('2')" >同意延期申请</el-button>
		</div>
		<div slot="footer" style="padding-left: 50px;" class="dialog-footer" v-else-if="obtainStatus == 6">
			<el-button type="primary" @click="gocancelTask('1')" >不同意申请</el-button>
			<el-button type="primary" @click="gocancelTask('2')" >同意取消申请</el-button>
		</div>

		<div slot="footer" class="dialog-footer" v-else>

		</div>
	</section>
</template>

<script>
    import util from '../../common/js/util'
	//import NProgress from 'nprogress'
    import { getTaskObtainDetail , getTaskApplyDetail, confirmTask, cancelTask, delayTask, updateTask } from '../../api/api';
    import moment from 'moment'

	export default {
		data() {
			return {
				id: '',
				detail: {},
				applyDetail: {},
				listLoading: false,
				
				obtainStatus: '',//0领取（未提交），1已提交，2后台提交给委托方，3申请延期，4延期开发中，5被退回修改中，6申请取消，7已取消，8审核通过，9已打款
				instruction: '',
				instruction1: '',
			}
		},
		methods: {
			task_status: function (value) {
				if(value == 1){
					return '进行中';
				}else{
					return '';
				}
			},
			detali_status: function (value) {
				if(value == 0){
					return '未提交';
				}else if(value == 1){
					return '已提交 未审核';
				}else if(value == 2){
					return '后台提交给委托方';
				}else if(value == 3){
					return '超时 申请延期';
				}else if(value == 4){
					return '延期开发中';
				}else if(value == 5){
					return '被退回修改中';
				}else if(value == 6){
					return '委托方 申请取消';
				}else if(value == 7){
					return '已取消';
				}else if(value == 8){
					return '审核通过';
				}else if(value == 9){
					return '已打款';
				}else{
					return '';
				}
			},
			//获取详情
			getDetail() {
				let para = {
					obtainId: this.$route.query.id
				};
				this.listLoading = true;
				getTaskObtainDetail(para).then((res) => {
					this.detail = res.data.out_data;
					var _obtainStatus = res.data.out_data.obtainStatus;
					this.obtainStatus = _obtainStatus;
					//this.obtainStatus = 3;

					this.listLoading = false;
					if(this.obtainStatus == 3){
						this.getApplyDetail();
					}else if(this.obtainStatus == 6){
						this.getApplyDetail();
					}else{

					}
				});
			},
			//获取审核详情
			getApplyDetail() {
				let para = {
					obtainId: this.$route.query.id,
					obtainStatus: this.obtainStatus
				};
				this.listLoading = true;
				getTaskApplyDetail(para).then((res) => {
                    this.applyDetail = res.data.out_data;
					this.listLoading = false;
				});
			},
			//审核(确认一个任务)
			goconfirmTask: function () {
				this.$confirm('确认审核通过吗？', '提示', {}).then(() => {
					let para = {
						obtainId: this.$route.query.id,
					};
					confirmTask(para).then(data=>{
						let {status,desc} = data;
						if(status == 0){
							this.$message({
								message: '提交成功',
								type: 'success'
							});
							this.getDetail();
						}else{
							this.$message({
								message: desc,
								type: 'error'
							});
						}
					});
				});
			},
			//审核(取消任务)
			gocancelTask: function (num) {
				var _text = '';
				if(num == 1){
					_text = '确认不同意申请？';
				}else{
					_text = '确认同意申请？';
				}
				this.$confirm(_text, '提示', {}).then(() => {
					this.$confirm('是否重新发布此任务？', '提示', {}).then(() => {
						let para = {
							obtainId: this.$route.query.id,
							createNew: 1,
							status: num
						};
						cancelTask(para).then(data=>{
							let {status,desc} = data;
							if(status == 0){
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.getDetail();
							}else{
								this.$message({
									message: desc,
									type: 'error'
								});
							}
						});
					}).catch(() => {
						let para = {
							obtainId: this.$route.query.id,
							createNew: 0,
							status: num
						};
						cancelTask(para).then(data=>{
							let {status,desc} = data;
							if(status == 0){
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.getDetail();
							}else{
								this.$message({
									message: desc,
									type: 'error'
								});
							}
						});
					});
				});
			},
			//审核(延期任务)
			godelayTask: function (num) {
				var _text = '';
				if(num == 1){
					_text = '确认不同意申请？';
				}else{
					_text = '确认同意申请？';
				}
				this.$confirm(_text, '提示', {}).then(() => {
					let para = {
						obtainId: this.$route.query.id,
						status: num
					};
					console.log(para);
					delayTask(para).then(data=>{
						let {status,desc} = data;
						if(status == 0){
							this.$message({
								message: '提交成功',
								type: 'success'
							});
							this.getDetail();
						}else{
							this.$message({
								message: desc,
								type: 'error'
							});
						}
					});
				});
			},
			//成品审核
			goupdateTask: function (num) {
				var _text = '';
				if(num == 1){
					_text = '确认不合格？';
				}else{
					_text = '确认合格？';
				}
				if(!this.instruction1){
					this.$message.error('请填写修改建议!');
				}else{
					this.$confirm(_text, '提示', {}).then(() => {
						let para = {
							obtainId: this.$route.query.id,
							instruction :this.instruction1,
							status: num
						};
						//console.log(para);
						updateTask(para).then(data=>{
							let {status,desc} = data;
							if(status == 0){
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.getDetail();
							}else{
								this.$message({
									message: desc,
									type: 'error'
								});
							}
						});
					});
				}
			}
		},
		mounted() {
			this.getDetail();
		}
	}

</script>

<style scoped>

</style>